/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package x10.interfaces.cm15a.receive;

import x10.utilities.ChunkOfBytes;
import x10.enums.Interfaces;
import x10.enums.Security;
import x10.event.X10SecurityCommand;
import x10.utilities.Utils;

/**
 *
 * @author Denny
 */
public class RFSecurityCommandMessage {
    private ChunkOfBytes bytes;

    public RFSecurityCommandMessage(ChunkOfBytes bytes){
        this.bytes = bytes;
    }

    public X10SecurityCommand parse(){
        X10SecurityCommand command = new X10SecurityCommand(getSecurityCode(), getCommand(), Interfaces.CM15A.toString());
        return command;
    }

    private Security getCommand(){
        return Security.getSecurity((int)bytes.getBytes()[4]);
//        byte command = message[4];
//        String returnCommand = null;
//
//        if(command == (byte)0x02){
//            returnCommand = "Delayed Arm Away";
//        } else if (command == (byte)0x82){
//            returnCommand = "Disarm";
//        } else if (command == (byte)0x42){
//            returnCommand = "Security Light On";
//        } else if (command == (byte)0xC2){
//            returnCommand = "Security Light Off";
//        } else if (command == (byte)0x22){
//            returnCommand = "Panic";
//        } else if (command == (byte)0x06){
//            returnCommand = "Arm Away";
//        } else if (command == (byte)0x0E){
//            returnCommand = "Arm Home/Register Device";
//        } else {
//            returnCommand = "Unknown";
//        }
//
//        return returnCommand;
    }

    private String getSecurityCode(){
        //Security code is in bytes 2 and 3 of the message

        byte high = bytes.getBytes()[2];
        byte low = bytes.getBytes()[3];

        return String.valueOf(Utils.getIntFromTwoBytes(high, low));
    }
}
